//
//  DataBaseHelper.m
//  aixuetang
//
//  Created by up72-2 on 15/7/14.
//  Copyright (c) 2015年 爱学堂. All rights reserved.
//

#import "DataBaseHelper.h"
#import "FMDatabase.h"
#import "FMDatabaseQueue.h"

@implementation DataBaseHelper
{
    FMDatabaseQueue *queue;
}

-(id) init
{
    self = [super init];
    if(self){
        queue = [FMDatabaseQueue databaseQueueWithPath:DBPath];
        
        [self inDatabase:^(FMDatabase *DB) {
            _db = DB;
        }];
    }
    return self;
}

//单例
+(DataBaseHelper*)sharedInstance
{
    static dispatch_once_t pred = 0;
    __strong static id _sharedObject = nil;
    dispatch_once(&pred, ^{
        _sharedObject = [[self alloc] init];
    });
    return _sharedObject;
}

-(void)inDatabase:(void(^)(FMDatabase*DB))block
{
    [queue inDatabase:^(FMDatabase *db){
        block(db);
    }];
}

@end
